<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * Mall
 */
namespace Mall\Controller;
use Common\Controller\AdminController;
Vendor('Qiniusdk.autoload'); //七牛入口文件引入 
use Qiniu\Auth; 
use Qiniu\Storage\UploadManager;
use Think\Upload;
use Qiniu\Processing\PersistentFop;
/**
 * 页面
 */
class PageController extends AdminController{
		
		
		
		public function index(){
			Vendor('Qny.autoload');
			// 用于签名的公钥和私钥
			$accessKey = '8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a';
			$secretKey = 'FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE';
			// 初始化签权对象
			$auth = new Auth($accessKey, $secretKey);
			// 空间名  https://developer.qiniu.io/kodo/manual/concepts
	//        p78151fwl.bkt.clouddn.com
			$bucket = 'music';
			// 生成上传Token
			$token = $auth->uploadToken($bucket);
			
			$this->assign("token",$token);
			$this->display();
		}
	
		public function get_bit(){
			#请求http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo   获取 bit_rate(码率)  >320k  无损   320k超品 128k高品  64k 流畅
			$bit_name = "http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo";
			$bit_result = file_get_contents($bit_name);
			$bit_array = json_decode($bit_result,true);
			
			$bit_rate = $bit_array['format']['bit_rate'];
			
			dump($bit_rate);
		}
		
		public function type_zhuanma($type,$bit,$result,$url){
			$m_mall_content_music = M("mall_content_music");
			#$type = 4;
			$this->upload_video($url,$type,$bit);
			$music_add['type'] = $type;
			$music_add['form_id'] = $result;
			$name_array = explode(".",$url);
			$music_add['url'] = "http://p7j34hu3o.bkt.clouddn.com/".$name_array[0]."_".$type.".mp3";
			$m_mall_content_music->add($music_add);
		}
		
		
		public function add_my($type,$result,$url){
			$m_mall_content_music = M("mall_content_music");
			$music_add['type'] = $type;
			$music_add['form_id'] = $result;
			$music_add['url'] = $url;
			$m_mall_content_music->add($music_add);
		}
		
		public function upload_video($key,$i,$bit_rate) {
			$accessKey = "8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a";
			$secretKey = "FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE";
			$bucket = "music";
			$auth = new Auth($accessKey, $secretKey);
			//要转码的文件所在的空间和文件名。
			#$key = '1527143791383.flac';
			//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline   1527231255422.flac
			$pipeline = 'music_zhuanma';
			$force = false;
			//转码完成后通知到你的业务服务器。
			$notifyUrl = 'http://music.liurizhao.zaiyoudao.com/music/port/qiniu.php';
			$config = new \Qiniu\Config();
			#dump($err);die;
			//$config->useHTTPS=true;
			$pfop = new PersistentFop($auth, $config);
			//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
			$name_array = explode(".",$key);
			
			$fops = "avthumb/mp3/ab/".$bit_rate."|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":".$name_array[0]."_".$i.".mp3");
			list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
			/* dump($bucket);
			dump($key);
			dump($fops);
			dump($pipeline);
			dump($notifyUrl);
			
			dump($err);
			die; */
			
			#暂时不用
			/* echo "\n====> pfop avthumb result: \n";
			if ($err != null) {
				var_dump($err);
			} else {
				echo "PersistentFop Id: $id\n";
			}
			//查询转码的进度和状态
			list($ret, $err) = $pfop->status($id);
			echo "\n====> pfop avthumb status: \n";
			if ($err != null) {
				var_dump($err);
			} else {
				var_dump($ret);
			} */
		}
	
	 public function get_token(){

        Vendor('Qny.autoload');
        // 用于签名的公钥和私钥
        $accessKey = '8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a';
        $secretKey = 'FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE';
        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);
        // 空间名  https://developer.qiniu.io/kodo/manual/concepts
//        p78151fwl.bkt.clouddn.com
        $bucket = 'music';
        // 生成上传Token
        $token = $auth->uploadToken($bucket);
		#echo $token;
		return $token;
	 }
	
	
	  public function upload(){

        Vendor('Qny.autoload');
        // 用于签名的公钥和私钥
        $accessKey = '8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a';
        $secretKey = 'FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE';
        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);
        // 空间名  https://developer.qiniu.io/kodo/manual/concepts
//        p78151fwl.bkt.clouddn.com
        $bucket = 'music';
        // 生成上传Token
        $token = $auth->uploadToken($bucket);
        // 构建 UploadManager 对象
        $uploadMgr = new UploadManager();
        // 上传文件到七牛
        $a=$_FILES['userfile'];
        $filePath = $a['tmp_name'];
        $houzhui=trim(strrchr($a['type'], '/'),'/');
        $url = 'http://p7j34hu3o.bkt.clouddn.com/';
        $key = time().rand(000,999).'.'.$houzhui;
		#http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo
        list($ret, $err) = $uploadMgr->putFile($token,$key,$filePath);
//        echo "\n====> putFile result: \n";
        if ($err !== null) {//上传出错
            var_dump($err);
        } else {//上传成功
            $true_url=$url.$ret['key'];
            //存入数据库
            //设置编辑器公共上传路径
            $userid = getUID()?getUID():0;
            $m_common_upload = M('common_upload');
            $m_common_upload_type = M('common_upload_type');

            //判断是否有类型没有用就新建

            $cutmap['title'] = $houzhui;
            $cutdata = $m_common_upload_type->where($cutmap)->find();

            if($cutdata){//找到了

                $cuttype = $cutdata['id'];
            }else{//没有
                $cutsdata['title'] = "$houzhui";
                $cutsdata['status'] = 1;
                $cuttype = $m_common_upload_type->add($cutsdata);


            }
            //判断用户
            $uid = $userid;
            //把上传内容存放入数据库
            $cudata =array(
                'status'=>1,
                'url'=> $true_url,
                'title'=>$key,
                'original'=>$a['name'],
                'type'=>$cuttype,
                'size'=>$a['size'],
                'time'=>time(),
                'uid'=>$uid,
            );
            $m_common_upload->add($cudata);

            echo($true_url);

        }
    }

	
	
	
	
	/**
	 * 单曲管理
	 */
    public function Manage(){

		common_public()->assign_page('菜单管理');
		
		//上传开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
			
		}else{
			
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			
			$map['name'] = array('like',"%$name%");

		}
		$this->assign('name',$name);
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		
		//selected="selected"
		$this->assign('uid',$uid);
		
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$m_cms_content = M('cms_content');
		$m_common_user = M('common_user');
		
		//获得上级信息
		$fmap['id'] = I('param.form_id')?I('param.form_id'):0;
		$fmap['type'] = get_cms_model_conf('CMS_PAGE');
		$fmap['status'] = 1;
		
		$data = $m_cms_content->where($fmap)->find();
		
		$search = I('param.search');
		//判断是否是搜索
		if(!$search){
			
			$map['form_id'] = $fmap['id'];
			
		}
		
		$map['type'] = get_cms_model_conf('CMS_PAGE');
		$map['status'] = 1;
		
		
		$list = $m_cms_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_cms_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			
			
			$umap['id'] = $list[$i]['uid'];
			
			$udata = $m_common_user->where($umap)->find();
			
			
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
		
		}
		//赋值
		$this->assign('list',$list);
		$this->assign('data',$data);
		$this->assign('form_id',$fmap['id']);
		
		
		$this->display();
	}
	
	
	
	/**
	 * 新增页面
	 */
	public function Create(){
		//判断是否是ajax请求 
		/* $accessKey = '8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a';
		$secretKey = 'FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE';
		$auth = new Auth($accessKey, $secretKey);
		$bucketName = 'music';
		$token = $auth->uploadToken($bucketName); */
		
		$m_mall_content = M("mall_content");
		$m_cms_style = M("cms_style");
		$m_mall_content_img = M("mall_content_img");
		$m_mall_content_music = M("mall_content_music");
		include_once 'upload.func.php';
		if(IS_POST){
			//获得数据
			$files = $_FILES['color_img']; 
			foreach($files as $i=>$v){
				foreach($files[$i] as $ii=>$vv){
					$files_list[$ii][$i] = $files[$i][$ii];
				}
			}
			$files = $files_list;
			
			foreach($files as $fileInfo) {  
				$res = uploadFile($fileInfo);  
				if(isset($res['dest'])) {  
					$uploadFiles[] = $res['dest'];  
				}  
			} 
			$str = '';
			$uploadFiles=array_filter($uploadFiles);
			
			$data = I();
			$style = $data['style'];
			$data['value'] = I('param.value','','');
			if($style){
				$data['style'] = implode(',',$data['style']);
			}
			$data['uid'] = getUID();
			$data['type'] = get_mall_model_conf('MALL_SINGLE');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = I('param.status');
			
			$result = $m_mall_content->add($data);
			if($result){
				#请求http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo   获取 bit_rate(码率)  >320k  无损   320k超品 128k高品  64k 流畅
				$bit_name = $data['mp3']."?avinfo";
				$bit_result = file_get_contents($bit_name);
				$bit_array = json_decode($bit_result,true);
				$bit_rate = $bit_array['format']['bit_rate'];
				
				#判断大小，对应转码
				$music_url = explode(".com/",$data['mp3']);
				$music_url = $music_url[1];
				
				if($bit_rate < 70000 and $bit_rate > 60000){
					$this->add_my(4,$result,$data['mp3']);
					$this->add_my(3,$result,"");
					$this->add_my(2,$result,"");
					$this->add_my(1,$result,"");
				}else if($bit_rate < 200000 and $bit_rate > 125000){
					$this->type_zhuanma(4,"64k",$result,$music_url);
					$this->add_my(3,$result,$data['mp3']);
					$this->add_my(2,$result,"");
					$this->add_my(1,$result,"");
				}else if($bit_rate < 340000 and $bit_rate > 300000){
					$this->type_zhuanma(4,"64k",$result,$music_url);
					$this->type_zhuanma(3,"128k",$result,$music_url);
					$this->add_my(2,$result,$data['mp3']);
					$this->add_my(1,$result,"");
				}else if($bit_rate > 340000){
					$this->type_zhuanma(4,"64k",$result,$music_url);
					$this->type_zhuanma(3,"128k",$result,$music_url);
					$this->type_zhuanma(2,"320k",$result,$music_url);
					$this->add_my(1,$result,$data['mp3']);
					#$this->type_zhuanma_ceshi(2,"320k",$result,$music_url);
				}
				
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					
					upload_file_name($img_name_list[$count - 1],$files[$i]['name'],$uploadFiles[$i],$files[$i]['size']);
					mall_img(1,$result,trim($uploadFiles[$i],'.'));
				}
			}
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(1,$result,$style); 
				
				$this->success('新增成功', U('Mall/Page/Create'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置
				$this->error('新增失败');
			}	
		}else{
			#查询语言
			$langue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			/* $this->assign("token",$token); */
			$this->assign("langue_list",$langue_list);
			$this->assign("style_list",$style_list);
			$this->display();
		}
		
	
	}
	/**
	 * 管理员新增单曲
	 */
	public function all_create(){
		//判断是否是ajax请求 
		/* $accessKey = '8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a';
		$secretKey = 'FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE';
		$auth = new Auth($accessKey, $secretKey);
		$bucketName = 'music';
		$token = $auth->uploadToken($bucketName); */
		
		$m_mall_content = M("mall_content");
		$m_cms_style = M("cms_style");
		$m_mall_content_img = M("mall_content_img");
		$m_common_user = M("common_user");
		include_once 'upload.func.php';
		if(IS_POST){
			
			$museic_user_id = I("param.museic_user_id");
			//获得数据
			$files = $_FILES['color_img']; 
			foreach($files as $i=>$v){
				foreach($files[$i] as $ii=>$vv){
					$files_list[$ii][$i] = $files[$i][$ii];
				}
			}
			$files = $files_list;
			
			foreach($files as $fileInfo) {  
				$res = uploadFile($fileInfo);  
				if(isset($res['dest'])) {  
					$uploadFiles[] = $res['dest'];  
				}  
			} 
			$str = '';
			$uploadFiles = array_filter($uploadFiles);
			
			$data = I();
			$style = $data['style'];
			$data['value'] = I('param.value','','');
			if($style){
				$data['style'] = implode(',',$data['style']);
			}
			$data['uid'] = $museic_user_id;
			$data['type'] = get_mall_model_conf('MALL_SINGLE');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = I('param.status');
			
			$result = $m_mall_content->add($data);
			if($result){
				
				#请求http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo   获取 bit_rate(码率)  >320k  无损   320k超品 128k高品  64k 流畅
				$bit_name = $data['mp3']."?avinfo";
				$bit_result = file_get_contents($bit_name);
				$bit_array = json_decode($bit_result,true);
				$bit_rate = $bit_array['format']['bit_rate'];
				
				#判断大小，对应转码
				$music_url = explode(".com/",$data['mp3']);
				$music_urls = $music_url[1];
				
				if($bit_rate < 70000 and $bit_rate > 60000){
					$this->add_my(4,$result,$data['mp3']);
					$this->add_my(3,$result,"");
					$this->add_my(2,$result,"");
					$this->add_my(1,$result,"");
				}else if($bit_rate < 200000 and $bit_rate > 125000){
					$this->type_zhuanma(4,"64k",$result,$music_urls);
					$this->add_my(3,$result,$data['mp3']);
					$this->add_my(2,$result,"");
					$this->add_my(1,$result,"");
				}else if($bit_rate < 340000 and $bit_rate > 300000){
					#修改路径为128k的
					album_save_url($result,$music_urls);
					
					$this->type_zhuanma(4,"64k",$result,$music_urls);
					$this->type_zhuanma(3,"128k",$result,$music_urls);
					$this->add_my(2,$result,$data['mp3']);
					$this->add_my(1,$result,"");
				}else if($bit_rate > 340000){
					#修改路径为128k的
					album_save_url($result,$music_urls);
					
					$this->type_zhuanma(4,"64k",$result,$music_urls);
					$this->type_zhuanma(3,"128k",$result,$music_urls);
					$this->type_zhuanma(2,"320k",$result,$music_urls);
					$this->add_my(1,$result,$data['mp3']);
				}
				
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					
					upload_file_name($img_name_list[$count - 1],$files[$i]['name'],$uploadFiles[$i],$files[$i]['size']);
					mall_img(1,$result,trim($uploadFiles[$i],'.'));
				}
			}
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(1,$result,$style); 
				
				$this->success('新增成功', U('Mall/Page/Create'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置
				$this->error('新增失败');
			}	
		}else{
			#查询语言
			$langue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			
			
			#查询所有音乐人
			$music_u_map['group_id'] = 9;
			$music_u_map['status'] = 1;
			$music_u_list = $m_common_user->where($music_u_map)->where($music_u_map)->field("id,nickname")->select();
			$this->assign("music_u_list",$music_u_list);
			$this->assign("langue_list",$langue_list);
			$this->assign("style_list",$style_list);
			$this->display();
		}
		
	
	}
	
	/**
	 * 页面详情
	 */
	public function Detail(){
    
		$m_cms_content = M('cms_content');
		
		common_public()->assign_page('页面详情');
		
		$map['id'] = I('param.id');
		$map['type'] = get_cms_model_conf('CMS_PAGE');
		$map['status'] = 1;
			
		$data = $m_cms_content->where($map)->find();
			
		$this->assign('data',$data);
		
			
		$this->display();
		
		
	
	}
	
	/**
	 * 编辑歌曲
	 */
	public function Edit_song(){
    
		$m_mall_content = M('mall_content');
		$m_mall_content_music = M('mall_content_music');
		
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){
			//获得数据
			
			$data = I('');
			unset($data['id']);
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			
			$result = $m_mall_content->where($map)->save($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']  
				$find_map['form_id'] = $map['id'];
				$find_map['url'] = $data['mp3'];
				$find_data = $m_mall_content_music->where($find_map)->find();
				
				if(!$find_data){
					#不相等的时候进行编码以及修改
					$result = $map['id'];
					#删除修改前转码的歌曲信息
					$delete_map['form_id'] = $result;
					$m_mall_content_music->where($delete_map)->delete();
					
					#请求http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo   获取 bit_rate(码率)  >320k  无损   320k超品 128k高品  64k 流畅
					$bit_name = $data['mp3']."?avinfo";
					$bit_result = file_get_contents($bit_name);
					$bit_array = json_decode($bit_result,true);
					$bit_rate = $bit_array['format']['bit_rate'];
					
					#判断大小，对应转码
					$music_url = explode(".com/",$data['mp3']);
					$music_urls = $music_url[1];
					
					if($bit_rate < 70000 and $bit_rate > 60000){
						$this->add_my(4,$result,$data['mp3']);
						$this->add_my(3,$result,"");
						$this->add_my(2,$result,"");
						$this->add_my(1,$result,"");
					}else if($bit_rate < 200000 and $bit_rate > 125000){
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->add_my(3,$result,$data['mp3']);
						$this->add_my(2,$result,"");
						$this->add_my(1,$result,"");
					}else if($bit_rate < 340000 and $bit_rate > 300000){
						#修改路径为128k的
						album_save_url($result,$music_urls);
						
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->type_zhuanma(3,"128k",$result,$music_urls);
						$this->add_my(2,$result,$data['mp3']);
						$this->add_my(1,$result,"");
					}else if($bit_rate > 340000){
						#修改路径为128k的
						album_save_url($result,$music_urls);
						
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->type_zhuanma(3,"128k",$result,$music_urls);
						$this->type_zhuanma(2,"320k",$result,$music_urls);
						$this->add_my(1,$result,$data['mp3']);
					}
					
					
				}
				
			
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(1,$map['id'],$style); 
				$this->success('编辑成功', U('Mall/Page/Song'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('编辑失败');
			
			}
		
		}else{
			#查询语言
			$langue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			#详情
			$map['type'] = get_mall_model_conf('MALL_SINGLE');
			$map['status'] = array("in",'2,4');
			$map['uid'] = getUID();
			$data = $m_mall_content->where($map)->find();
			$style_list = if_style($style_list,$data['style']);
			
			$this->assign('langue_list',$langue_list);
			$this->assign('style_list',$style_list);
			$this->assign('data',$data);
			
			$this->display();
		}
	}
	
	/**
	 * 编辑歌曲
	 */
	public function Edit_all_song(){
    
		$m_mall_content = M('mall_content');
		$m_mall_content_music = M('mall_content_music');
		
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){
			//获得数据
			
			$data = I('');
			unset($data['id']);
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$result = $m_mall_content->where($map)->save($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']  
			
				$find_map['form_id'] = $map['id'];
				$find_map['url'] = $data['mp3'];
				$find_data = $m_mall_content_music->where($find_map)->find();
				
				if(!$find_data){
					#不相等的时候进行编码以及修改
					$result = $map['id'];
					#删除修改前转码的歌曲信息
					$delete_map['form_id'] = $result;
					$m_mall_content_music->where($delete_map)->delete();
					
					#请求http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo   获取 bit_rate(码率)  >320k  无损   320k超品 128k高品  64k 流畅
					$bit_name = $data['mp3']."?avinfo";
					$bit_result = file_get_contents($bit_name);
					$bit_array = json_decode($bit_result,true);
					$bit_rate = $bit_array['format']['bit_rate'];
					
					#判断大小，对应转码
					$music_url = explode(".com/",$data['mp3']);
					$music_urls = $music_url[1];
					
					if($bit_rate < 70000 and $bit_rate > 60000){
						$this->add_my(4,$result,$data['mp3']);
						$this->add_my(3,$result,"");
						$this->add_my(2,$result,"");
						$this->add_my(1,$result,"");
					}else if($bit_rate < 200000 and $bit_rate > 125000){
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->add_my(3,$result,$data['mp3']);
						$this->add_my(2,$result,"");
						$this->add_my(1,$result,"");
					}else if($bit_rate < 340000 and $bit_rate > 300000){
						#修改路径为128k的
						album_save_url($result,$music_urls);
						
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->type_zhuanma(3,"128k",$result,$music_urls);
						$this->add_my(2,$result,$data['mp3']);
						$this->add_my(1,$result,"");
					}else if($bit_rate > 340000){
						#修改路径为128k的
						album_save_url($result,$music_urls);
						
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->type_zhuanma(3,"128k",$result,$music_urls);
						$this->type_zhuanma(2,"320k",$result,$music_urls);
						$this->add_my(1,$result,$data['mp3']);
					}
				}
				
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(1,$map['id'],$style); 
				$this->success('编辑成功', U('Mall/Page/Song'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('编辑失败');
			
			}
		}else{
			#查询语言
			$langue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			#详情
			$map['type'] = get_mall_model_conf('MALL_SINGLE');
			$map['status'] = array("in",'1,2,3,4');
			#$map['uid'] = getUID();
			$data = $m_mall_content->where($map)->find();
			$style_list = if_style($style_list,$data['style']);
			
			$this->assign('langue_list',$langue_list);
			$this->assign('style_list',$style_list);
			$this->assign('data',$data);
			
			$this->display();
		}
	}
	
	/**
	 * 批量改变页面状态
	 */
	public function Delete($id,$status=0){
		
	
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_mall_content = M('mall_content');
			
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				
			
				$id = explode(',',$id); 
				
				
				foreach($id as $i=>$k){
					
					
					$map['id'] = $id[$i];
					$data['status'] = $status;
					
					$m_mall_content->where($map)->save($data);
					
				}
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
			
	
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);


	}
	
	
	
	/**
	 * 批量改变页面状态
	 */
	public function Delete_ranking($id,$status=0){
		
		//判断是否是ajax请求
		if(IS_AJAX){
			$m_common_user_ranking = M("common_user_ranking");
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['status'] = $status;
					$m_common_user_ranking->where($map)->save($data);
				}
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
	}
	
	
	
	/**
	 * 页面管理
	 */
    public function banner(){

		//页面配置
		$page = array(
			'title'=>'页面管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		$this->assign('page',$page);
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		
		//判断是否搜索标题
		$name = I('param.name');
		if($name){
			
			$map['name'] = array('like',"%$name%");

		}
		$this->assign('name',$name);
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		
		//selected="selected"
		$this->assign('uid',$uid);
		
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$m_cms_content = M('cms_content');
		$m_common_user = M('common_user');
		
		//获得上级信息
		$fmap['id'] = I('param.form_id')?I('param.form_id'):0;
		$fmap['type'] = get_cms_model_conf('CMS_PAGE');
		$fmap['status'] = 1;
		
		$data = $m_cms_content->where($fmap)->find();
		
		$search = I('param.search');
		//判断是否是搜索
		if(!$search){
			
			$map['form_id'] = $fmap['id'];
			
		}
		$map['type'] = get_cms_model_conf('CMS_PAGE');
		$map['status'] = 1;
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_cms_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_cms_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			
			
			$umap['id'] = $list[$i]['uid'];
			
			$udata = $m_common_user->where($umap)->find();
			
			$map_num['form_id'] = $list[$i]['id'];
			$map_num['type'] = get_cms_model_conf('CMS_PAGE');;
			$map_num['status'] = 1;
			$list[$i]['num'] = $m_cms_content->where($map_num)->count();
			
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
		
		}
		//赋值
		$this->assign('list',$list);
		$this->assign('data',$data);
		$this->assign('form_id',$fmap['id']);
		
		
		$this->display();
	}
	
	/**
	 * 页面管理
	 */
    public function Song(){

		//页面配置
		$page = array(
			'title'=>'单曲管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['uid'] = getUID();
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
		}
		#dump($list);die;
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	
	
	/**
	 *单曲管理
	 */
    public function all_song(){
		//页面配置
		$page = array(
			'title'=>'单曲管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		
		//判断是否搜索名称
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			$list[$i]['style'] = style_str($list[$i]['style']);
			
		}
		//dump($list);die;
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		#获取所有音乐人
		$all_music_user = music_user();
		
		$this->assign("all_music_user",$all_music_user);
		$this->display();
	}
	
	/**
	 *单曲管理
	 */
    public function no_song(){
		//页面配置
		$page = array(
			'title'=>'单曲管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		
		//判断是否搜索名称
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['status'] = array("in",'3');
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
			$list[$i]['style_name'] = style_str($list[$i]['style_name']);
		}
		#dump($list);die;
		//赋值
		$this->assign('list',$list);
		
		$this->display();
	}
	
	
	/**
	 * 推荐管理
	 */
    public function tui_song(){
		//页面配置
		$page = array(
			'title'=>'推荐管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		
		//判断是否搜索名称
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['status'] = array("in",'1');
		$map['recommended'] = array("in",'1');
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
			$list[$i]['style_name'] = style_str($list[$i]['style']);
		}
		#dump($list);die;
		//赋值
		$this->assign('list',$list);
		
		$this->display();
	}
	
	
	/**
	 *活动列表 
	 */
    public function Activity(){

		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		//页面配置
		$page = array(
			'title'=>'活动列表',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
		$map['uid'] = getUID();
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_mall_content ->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content ->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$style_name = array();
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
			$list[$i]['style_name'] = style_str($list[$i]['style']);
		
		}
		
		//dump($list);die;
		//赋值
		$this->assign('list',$list);
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	/* 专辑歌曲管理 */
	public function album_song(){
		
		$this->display();
	}
	
	/* 新增歌曲 */
	public function music_create(){
		
		$this->display();
	}
	
	
		
	/* 新增活动 */
	public function create_activity_user(){
		include_once 'upload.func.php';
		$m_mall_content = M("mall_content");
		$m_mall_content_money = M("mall_content_money");
		$m_common_user = M("common_user");
		if(IS_POST){
			$museic_user_id = I("param.museic_user_id");
			//dump(I());die;
			/* $files = getFiles(); 
			foreach($files as $fileInfo) {  
				$res = uploadFile($fileInfo);  
				if(isset($res['dest'])) {  
					$uploadFiles[] = $res['dest'];  
				}  
			}
			$str = '';
			$uploadFiles=array_filter($uploadFiles);
			foreach($uploadFiles as $i=>$v){
				$img_name_list = explode("/",$uploadFiles[$i]);
				$count = count($img_name_list);
				$str_str = substr($uploadFiles[$i],1);
				//dump($str_str);die;
				if($i == 0){
					$str .= $str_str;
				}else{
					$str .= ','.$str_str;
				}
				upload_file_name($img_name_list[$count - 1],$files[$i]['name'],$uploadFiles[$i],$files[$i]['size']);
			} */
			$value = I('param.value','','');
		
			 $pattern_img = '/<img (.+?)\/>/';
			 preg_match_all($pattern_img,$value,$matches_img);
			 
			 $pattern_src = '/src="(.+?)"/';
			foreach($matches_img[1] as $ii=>$vv){
				preg_match_all($pattern_src,$vv,$matches_src);
				$img_url = if_url($matches_src[1][0]);
				if($img_url){
					$matches_src_list_jiequ[] = cut_image($img_url);
					$matches_src_list[] = $img_url;
				}
				
			}
			$matches_src_str = implode(",",$matches_src_list);
			//获得数据
			$data = I();
			$data['url'] = $matches_src_str;
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			$data['uid'] = $museic_user_id;
			$data['type'] = get_mall_model_conf('MALL_ACTIVITY');
			$data['time'] = time();
			$data['release_time'] = strtotime(I("param.release_time"));
			$data['ip'] = get_client_ip();
			$data['status'] = 2;
			$result = $m_mall_content->add($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
				#添加相册
				foreach($matches_src_list as $i=>$v){
					mall_img(5,$result,trim($matches_src_list[$i],'.'));
				}
				
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(3,$result,$style); 
				#创建价格
				$begin_array = I('param.huodong_begin');
				$end_array = I('param.huodong_end');
				$money_array = I('param.huodong_money');
				$name_array = I('param.huodong_name');
				$number = I('param.number');
				foreach($begin_array as $i=>$v){
					$add_begin['begin_time'] = strtotime($begin_array[$i]);
					$add_begin['end_time'] = strtotime($end_array[$i]);
					$add_begin['goods_money'] = $money_array[$i];
					$add_begin['name'] = $name_array[$i];
					$add_begin['number'] = $number[$i];
					$add_begin['goods_id'] = $result;	
					$m_mall_content_money->add($add_begin);
				}
				
				$this->success('新增成功', U('Mall/Page/activity'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置
				$this->error('新增失败');
			}	
		}else{
			
			#查询流派风格
			$style_list = gettypes();
			
			#查询所有音乐人
			$music_u_map['group_id'] = 9;
			$music_u_map['status'] = 1;
			$music_u_list = $m_common_user->where($music_u_map)->where($music_u_map)->field("id,nickname")->select();
			
			
			#dump($langeue_str);die; 
			$this->assign("music_u_list",$music_u_list);
			
			/* $this->assign("token",$token); */
			$this->assign("style_list",$style_list);
			$this->display();
		}
	}
	/* 新增活动 */
	public function create_activity(){
		include_once 'upload.func.php';
		$m_mall_content = M("mall_content");
		$m_mall_content_money = M("mall_content_money");
		
		if(IS_POST){
			$value = I('param.value','','');
		
			 $pattern_img = '/<img (.+?)\/>/';
			 preg_match_all($pattern_img,$value,$matches_img);
			 
			 $pattern_src = '/src="(.+?)"/';
			foreach($matches_img[1] as $ii=>$vv){
				preg_match_all($pattern_src,$vv,$matches_src);
				$img_url = if_url($matches_src[1][0]);
				if($img_url){
					$matches_src_list_jiequ[] = cut_image($img_url);
					$matches_src_list[] = $img_url;
				}
				
			}
			$matches_src_str = implode(",",$matches_src_list);
			
			$number = I('param.number');
			
			//获得数据
			$data = I();
			$data['url'] = $matches_src_str;
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			$data['uid'] = getUID();
			$data['type'] = get_mall_model_conf('MALL_ACTIVITY');
			$data['time'] = time();
			$data['release_time'] = strtotime(I("param.release_time"));
			
			$data['ip'] = get_client_ip();
			$data['status'] = 2;
			$result = $m_mall_content->add($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
				#添加相册
				foreach($matches_src_list as $i=>$v){
					mall_img(5,$result,trim($matches_src_list[$i],'.'));
				}
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(3,$result,$style); 
				#创建价格
				$begin_array = I('param.huodong_begin');
				$end_array = I('param.huodong_end');
				$money_array = I('param.huodong_money');
				$name_array = I('param.huodong_name');
				
				foreach($begin_array as $i=>$v){
					$add_begin['begin_time'] = strtotime($begin_array[$i]);
					$add_begin['end_time'] = strtotime($end_array[$i]);
					$add_begin['goods_money'] = $money_array[$i];
					$add_begin['name'] = $name_array[$i];
					$add_begin['number'] = $number[$i];
					/* $add_begin['number'] = 100; */
					$add_begin['goods_id'] = $result;	
					$m_mall_content_money->add($add_begin);
				}
				$this->success('新增成功', U('Mall/Page/activity'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置
				$this->error('新增失败');
			}	
		}else{
			
			#查询流派风格
			$style_list = gettypes();
			
			/* $this->assign("token",$token); */
			$this->assign("style_list",$style_list);
			$this->display();
		}
	}
	
	/* 管理全部歌曲 */
	public function all_album_song(){
		
		$this->display();
	}
	
	
	/* 管理全部活动  */
	public function all_activity(){
		
		//页面配置
		$page = array(
			'title'=>'活动列表',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';
		if($uid!=0){
			$map['uid'] =array('like',"%$uid%");
		}
		//selected="selected"
		$this->assign('uid',$uid);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
		$map['status'] = array("in",'1,2,3,4');
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_mall_content ->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content ->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//dump($list );die;
		//查询关联信息
		foreach($list as $i=>$k){
			
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
			$list[$i]['style_name'] = style_str($list[$i]['style']);
		}
		#dump($list);die;
		//赋值
		$this->assign('list',$list);
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	/* 管理全部活动  */
	public function tui_activity(){
		
		//页面配置
		$page = array(
			'title'=>'活动列表',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';
		if($uid!=0){
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
		$map['status'] = array("in",'1');
		$map['recommended'] = array("in",'1');
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_mall_content ->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content ->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//dump($list );die;
		//查询关联信息
		foreach($list as $i=>$k){
			
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
			$list[$i]['style_name'] = style_str($list[$i]['style']);
		}
		#dump($list);die;
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	
	/* 排序单曲推荐位置 */
	public function r_activity(){
		$m_mall_content = M('mall_content');
		if(IS_AJAX){
			
			$map['id'] = I("param.id");
			$data['sort'] = I("param.sort");
			if(!empty($map['id'])){
				$result = $m_mall_content->where($map)->save($data);
				if($result){
					$info = 1;
				}else{
					$info = 2;
				}
			}else{
				$info = 3;
			}
			
		}else{
			$info = 4;
		}
		$this->ajaxReturn($info);
	}
	
	/* 排序单曲推荐位置---PM */
	public function pm_activity(){
		$m_mall_content = M('mall_content'); 
		if(IS_AJAX){
			
			$map['id'] = I("param.id");
			$data['pm_sort'] = I("param.sort");
			if(!empty($map['id'])){
				$result = $m_mall_content->where($map)->save($data); 
				if($result){
					$info = 1;
				}else{
					$info = 2;
				}
			}else{
				$info = 3;
			}
			
		}else{
			$info = 4;
		}
		$this->ajaxReturn($info);
	}
	
	/* 管理全部活动  */
	public function no_activity(){
		
		//页面配置
		$page = array(
			'title'=>'活动列表',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';
		if($uid!=0){
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
		$map['status'] = 3;
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_mall_content ->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content ->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//dump($list );die;
		//查询关联信息
		foreach($list as $i=>$k){
			
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
			$list[$i]['style_name'] = style_str($list[$i]['style_name']);
		}
		#dump($list);die;
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	
	/* 管理推荐活动 */
	public function Best_activity(){
		
		$this->display();
	}
	
	/* 管理推荐单曲 */
	public function Best_song(){
		
		$this->display();
	}
	
	
	/* 编辑活动 */
	public function Edit_activity(){
		$m_mall_content = M('mall_content');
		$m_mall_content_img = M('mall_content_img');
		$m_mall_content_money = M('mall_content_money');
		include_once 'upload.func.php';
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){
			
			
			$value = I('param.value','','');
		
			 $pattern_img = '/<img (.+?)\/>/';
			 preg_match_all($pattern_img,$value,$matches_img);
			 
			 $pattern_src = '/src="(.+?)"/';
			foreach($matches_img[1] as $ii=>$vv){
				preg_match_all($pattern_src,$vv,$matches_src);
				$img_url = if_url($matches_src[1][0]);
				if($img_url){
					$matches_src_list_jiequ[] = cut_image($img_url);
					$matches_src_list[] = $img_url;
				}
				
			}
			$matches_src_str = implode(",",$matches_src_list);
			
			
			//获得数据
			$data = I();
			$data['url'] = $matches_src_str;
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			/* $data['uid'] = getUID(); */
			$data['time'] = time();
			$data['release_time'] = strtotime(I("param.release_time"));
			$data['ip'] = get_client_ip();
			$m_mall_content->where($map)->save($data);
				$delete_img['status'] = 1;
				$delete_img['type'] = 5;
				$delete_img['form_id'] = $map['id'];
				
				$save_img['status'] = 0;
				$save_result = $m_mall_content_img->where($delete_img)->save($save_img);
				
				#添加相册
				foreach($matches_src_list as $i=>$v){
					mall_img(5,$map['id'],trim($matches_src_list[$i],'.'));
				}
				
				
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(3,$map['id'],$style); 
				#创建价格
				$begin_array = I('param.huodong_begin');
				$end_array = I('param.huodong_end');
				$money_array = I('param.huodong_money');
				$name_array = I('param.huodong_name');
				$number = I('param.number');
				foreach($begin_array as $i=>$v){
					$add_begin['begin_time'] = strtotime($begin_array[$i]);
					$add_begin['end_time'] = strtotime($end_array[$i]);
					$add_begin['goods_money'] = $money_array[$i];
					$add_begin['name'] = $name_array[$i];
					$add_begin['number'] = $number[$i];
					$add_begin['goods_id'] = $map['id'];	
					$m_mall_content_money->add($add_begin);
				}
			$this->success('编辑成功', U('Mall/Page/activity'));
		}else{
			
			$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
			$map['status'] = array('in','2,4');
			$map['uid'] = getUID();
			$data = $m_mall_content->where($map)->find();
			
			#查询价格
			$money_map['goods_id'] = $data['id'];
			$money_list = $m_mall_content_money->where($money_map)->select();
			
			#流派风格
			$style_list = gettypes();
			
			$style_list = if_style($style_list,$data['style']);
			#dump($style_list);die;
			
			$this->assign('data',$data);
			$this->assign('style_list',$style_list);
			$this->assign('money_list',$money_list);
			$this->display();
		}
	}
	
	
	/* 管理员编辑活动 */
	public function Edit_all_activity(){
		$m_mall_content = M('mall_content');
		$m_mall_content_money = M('mall_content_money');
		$m_mall_content_img = M('mall_content_img');
		include_once 'upload.func.php';
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){
			
			$value = I('param.value','','');
		
			 $pattern_img = '/<img (.+?)\/>/';
			 preg_match_all($pattern_img,$value,$matches_img);
			 
			 $pattern_src = '/src="(.+?)"/';
			foreach($matches_img[1] as $ii=>$vv){
				preg_match_all($pattern_src,$vv,$matches_src);
				$img_url = if_url($matches_src[1][0]);
				if($img_url){
					$matches_src_list_jiequ[] = cut_image($img_url);
					$matches_src_list[] = $img_url;
				}
				
			}
			$matches_src_str = implode(",",$matches_src_list);
			
			//获得数据
			$data = I();
			$data['url'] = $matches_src_str;
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			/* $data['uid'] = getUID(); */
			$data['time'] = time();
			$data['release_time'] = strtotime(I("param.release_time"));
			$data['ip'] = get_client_ip();
			$m_mall_content->where($map)->save($data);
				$delete_img['status'] = 1;
				$delete_img['type'] = 5;
				$delete_img['form_id'] = $map['id'];
				
				$save_img['status'] = 0;
				$save_result = $m_mall_content_img->where($delete_img)->save($save_img);
				
				#添加相册
				foreach($matches_src_list as $i=>$v){
					mall_img(5,$map['id'],trim($matches_src_list[$i],'.'));
				}
				
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(3,$map['id'],$style); 
				#创建价格
				$begin_array = I('param.huodong_begin');
				$end_array = I('param.huodong_end');
				$money_array = I('param.huodong_money');
				$name_array = I('param.huodong_name');
				$number = I('param.number');
				foreach($begin_array as $i=>$v){
					$add_begin['begin_time'] = strtotime($begin_array[$i]);
					$add_begin['end_time'] = strtotime($end_array[$i]);
					$add_begin['goods_money'] = $money_array[$i];
					$add_begin['name'] = $name_array[$i];
					$add_begin['number'] = $number[$i];
					$add_begin['goods_id'] = $map['id'];	
					$m_mall_content_money->add($add_begin);
				}
			$this->success('编辑成功', U('Mall/Page/All_activity'));
		}else{
			
			$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
			#$map['status'] = array('in','2,4');
			#$map['uid'] = getUID();
			$data = $m_mall_content->where($map)->find();
			
			#查询价格
			$money_map['goods_id'] = $data['id'];
			$money_list = $m_mall_content_money->where($money_map)->select();
			
			#流派风格
			$style_list = gettypes();
			$style_list = if_style($style_list,$data['style']);
			#dump($style_list);die;
			
			$this->assign('data',$data);
			$this->assign('style_list',$style_list);
			$this->assign('money_list',$money_list);
			$this->display();
		}
	}
	
	#加入推荐
	public function recommended($id,$recommended=0){
		//判断是否是ajax请求
		if(IS_AJAX){
			$m_mall_content = M('mall_content');
			
			$id = $id?$id:I('param.id');
			$recommended= $recommended?$recommended:I('param.recommended');
			
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data_data = $m_mall_content->where($map)->find();
					if($data_data['status'] == 1){
						$data['recommended'] = $recommended;
						$m_mall_content->where($map)->save($data);
					}
					
				}
				
				//返回信息
				$info = get_errcode(0);
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
		
	}
	
	
	
	/**
	 * 页面管理
	 */
    public function set_playlist(){
		//页面配置
		$page = array(
			'title'=>'单曲管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['uid'] = getUID();
		$map['status'] = 1;
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
		}
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		
		#歌单列表
		$playlist_map['type'] = get_mall_model_conf('MALL_PLAYLIST');
		$playlist_map['uid'] = getUID();
		$playlist_map['status'] = 1;
		$playlist_list = $m_mall_content->where($playlist_map)->select();
		$this->assign('playlist_list',$playlist_list);
		$this->display();
	}
	
	/**
	 * 页面管理
	 */
    public function playlist_details(){
		//页面配置
		$page = array(
			'title'=>'歌单详情',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$details_map['id'] = I("param.id");
		$details_map['status'] = 1;
		$details_map['type'] = 20;
		$details_data = $m_mall_content->where($details_map)->find();
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['status'] = 1;
		$map['uid'] = getUID();
		$map['id'] = array("in",$details_data['value']);
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
		}
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		
		#歌单id
		$this->assign("details_data",$details_data);
		
		$this->display();
	}
	
	
	/**
	 * 歌单列表（音乐人）
	 */
    public function playlist(){
		$m_mall_content = M('mall_content');
		
		//获得菜单信息
		$map['type'] = get_mall_model_conf('MALL_PLAYLIST');
		$map['uid'] = getUID();
		$map['status'] = 1;
		$list = $m_mall_content->where($map)->order('sort desc')->select();
		
		$style_list = gettypes();
		foreach($list as $i=>$v){
			#风格查询
			
			$style_list = if_style($style_list,$list[$i]['style']);
		}
		
		
		//dump($style_list);die;
		//赋值
		$this->assign('list',$list);
		$this->assign('style_list',$style_list);
		$this->assign('style_lists',$style_list);
		$this->display();
	}
	
	/**
	 * 音乐人歌单列表（管理员）
	 */
    public function musicians_playlist(){
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		$u_map['group_id'] = array("gt",2);
		$u_map['status'] = 1;
		$u_list = $m_common_user->where($u_map)->field("id")->select();
		$u_array = array_column($u_list,"id");
		$u_str = implode(",",$u_array);
		
		//获得菜单信息
		$map['type'] = get_mall_model_conf('MALL_PLAYLIST');
		$map['status'] = 1;
		$map['uid'] = array('in',$u_str);
		
		$list = $m_mall_content->where($map)->order('sort desc')->select();
		foreach($list as $i=>$v){
			$user_map['id'] = $list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$list[$i]['username'] = $user_data['nickname'];
		}
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	
	/**
	 * 新增菜单
	 */
	public function Create_playlist(){
		
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			//获得数据
			$style = I("param.style");
			
			$data = I();
			
			$data['uid'] = getUID();
			$data['type'] = get_mall_model_conf('MALL_PLAYLIST');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = 1;
			$data['style'] = implode(',',$style);
			$result = $m_mall_content->add($data);
			if($result){
				add_style(6,$result,$style);
			}
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 编辑菜单
	 */
	public function Edit_playlist(){
    
	
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			$map['id'] = I('param.id');
			$map['uid'] = getUID();
			$data = I('');
			unset($data['id']);
			$style = I("param.style");
			$data['style'] = implode(',',$style);
			add_style(6,$map['id'],$style);
			
			$result = $m_mall_content->where($map)->save($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 批量删除菜单
	 */
	public function Delete_playlist($id,$status=0){
		
	
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_mall_content = M('mall_content');
		
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['status'] = $status;
					$m_mall_content->where($map)->save($data);
					
				}
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
	}
	
	
	/**
	 * 批量加入歌单,取消加入
	 * $id 为加入或者取消ID   $status = 1 为加入  2为取消   $playlist_id 为目标歌单
	 */
	public function add_playlist(){
		
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_mall_content = M('mall_content');
		
			$id = I('param.id');
			$status = I("param.status");
			$playlist_id = I("param.playlist_id");
			
			if(!empty($id) and !empty($status) and !empty($playlist_id)){
				$map['id'] = $playlist_id;
				$map['type'] = 20;   //歌单
				$data = $m_mall_content->where($map)->find();
				
				$playlist_array = explode(',',$data['value']);
				$id_array = explode(',',$id);
				if($status == 1){
					#两个数组去重，避免重复
					$array_array = array_keys(array_flip($playlist_array)+array_flip($id_array));
					$save_data['value'] = implode(',',$array_array);
					$save_data['value'] = trim($save_data['value'],',');
					
				}else{
					$array_array = array_diff($playlist_array,$id_array);
					$save_data['value'] = implode(',',$array_array);
				}
				$result = $m_mall_content->where($map)->save($save_data);
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
	}
	
	
	/**
	 * 歌单列表（管理员）
	 */
    public function all_playlist(){
		$m_mall_content = M('mall_content');
		
		//获得菜单信息
		$admin_uid = admin_uid();
		$map['type'] = get_mall_model_conf('MALL_PLAYLIST');
		$map['status'] = 1;
		$map['uid'] = array("in",$admin_uid);
		$list = $m_mall_content->where($map)->order('sort desc')->select();
		
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	/**
	 * 歌单推荐列表（管理员）
	 */
    public function tui_playlist(){
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		$admin_uid = admin_uid();
		//获得菜单信息
		$admin_uid = admin_uid();
		$map['type'] = get_mall_model_conf('MALL_PLAYLIST');
		$map['status'] = 1;
		$map['recommended'] = 1;
		$map['uid'] = array("in",$admin_uid);
		$list = $m_mall_content->where($map)->order('sort desc')->select();
		foreach($list as $i=>$v){
			$u_map['id'] = $list[$i]['uid'];
			$u_data = $m_common_user->where($u_map)->find();
			$list[$i]['username'] = $u_data['nickname'];
		}
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	
	
	/**
	 * 新增菜单
	 */
	public function all_create_playlist(){
		
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			//获得数据
			$data = I();
			$data['uid'] = getUID();
			$data['type'] = get_mall_model_conf('MALL_PLAYLIST');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = 1;
			
			$result = $m_mall_content->add($data);
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	
	/**
	 * 编辑菜单
	 */
	public function all_edit_playlist(){
    
	
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			$map['id'] = I('param.id');
			
			$data = I('');
			unset($data['id']);
		
			$result = $m_mall_content->where($map)->save($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 页面管理
	 */
    public function all_set_playlist(){
		//页面配置
		$page = array(
			'title'=>'单曲管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		#所有管理员的发布 admin_uid();
		$admin_uid = admin_uid();
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['status'] = 1;
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
		}
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		
		#歌单列表   所有管理员创建
		$playlist_map['type'] = get_mall_model_conf('MALL_PLAYLIST');
		$playlist_map['uid'] = array("in",$admin_uid);
		$playlist_map['status'] = 1;
		$playlist_list = $m_mall_content->where($playlist_map)->select();
		$this->assign('playlist_list',$playlist_list);
		$this->display();
	}
	
	/**
	 * 页面管理
	 */
    public function all_playlist_details(){
		//页面配置
		$page = array(
			'title'=>'歌单详情',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$details_map['id'] = I("param.id");
		$details_map['status'] = 1;
		$details_map['type'] = 20;
		$details_data = $m_mall_content->where($details_map)->find();
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['status'] = 1;
		$map['id'] = array("in",$details_data['value']);
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
		}
		//赋值
		$this->assign('list',$list);
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		#歌单id
		$this->assign("details_data",$details_data);
		$this->display();
	}
	
	/**
	 * 文章管理
	 */
    public function ranking(){

		//页面配置
		$page = array(
			'title'=>'排行管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		$this->assign('page',$page);
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		$m_common_user_ranking = M('common_user_ranking');
		
		$map['status'] = array("in",'1,2');
		$map['form_id'] = 0;
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_common_user_ranking->where($map)->order('time desc')->page($_GET['p'].',50')->select();
	
		$count      = $m_common_user_ranking->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	
	public function Create_ranking(){
		$m_cms_content = M("cms_content");
		$m_mall_content = M("mall_content");
		$m_common_user_ranking = M("common_user_ranking");
		
		if(IS_POST){
			$data = I("");
			$data['time'] = time();
			$data['status'] = 2;
			$result = $m_common_user_ranking->add($data);
			
			if($result){
				$this->success('新增成功', U('Mall/Page/ranking'));
			}else { 
				$this->error('新增失败');
			}	
			
			//dump($data);die;
		}else{
			/* #风格
			$style_map['type'] = get_mall_model_conf('MALL_STYLE');
			$style_map['status'] = 1;
			$style_list = $m_mall_content->where($style_map)->select();
			
			#排行类型
			$rtyle_style_map['type'] = get_cms_model_conf('CMS_RANKING_STYLE');
			$rtyle_style_map['status'] = 1;
			$rtyle_style_list = $m_cms_content->where($rtyle_style_map)->select();
			
			#时间
			$time_map['type'] = get_cms_model_conf('CMS_TIME');
			$time_map['status'] = 1;
			$time_list = $m_cms_content->where($time_map)->select();
			
			#排行的种类  单曲、专辑、音乐人
			$type_map['type'] = get_cms_model_conf('CMS_RANKING_TYPE');
			$type_map['status'] = 1;
			$type_list = $m_cms_content->where($type_map)->select();
			
			$this->assign("style_list",$style_list);
			$this->assign("rtyle_style_list",$rtyle_style_list);
			$this->assign("time_list",$time_list);
			$this->assign("type_list",$type_list); */
			$this->display();	
		}
		
	}
	public function Edit_ranking(){
		$m_common_user_ranking = M("common_user_ranking");
		
		$map['id'] = I("param.id");
		if(IS_POST){
			
			$data = I("");
			$data['time'] = time();
			unset($data['id']);
			$result = $m_common_user_ranking->where($map)->save($data);
			
			if($result){
				$this->success('编辑成功', U('Mall/Page/ranking'));
			}else { 
				$this->error('编辑失败');
			}	
			
			
		}else{
			$map['status'] = array("neq",'0');
			$data = $m_common_user_ranking->where($map)->find();
			
			$this->assign("data",$data);
			$this->display();	
		}
		
	}
	
	#排行榜内列表
	public function Ranking_list(){
		$m_common_user_ranking = M("common_user_ranking");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		#查询排行榜名称信息
		$f_map['id'] = I("param.id");
		$f_map['form_id'] = 0;
		$f_map['status'] = array("in",'1,2');
		$f_data = $m_common_user_ranking->where($f_map)->find();
		
		#列表信息
		$map['form_id'] = I("param.id");
		$map['status'] = 1;
		$map['type'] = $f_data['type'];
		$list = $m_common_user_ranking->where($map)->select();
		
		#判断是  音乐人   还是   单曲或者专辑   
		if($f_data['type'] == 1 or $f_data['type'] == 2){
			#单曲 或者专辑
			foreach($list as $i=>$v){
				$c_map['id'] = $list[$i]['target_id'];
				$c_data = $m_mall_content->where($c_map)->find();
				$list[$i]['target_name'] = $c_data['name'];
			}
			
		}else{
			#活动
			foreach($list as $i=>$v){
				$u_map['id'] = $list[$i]['target_id'];
				$u_map = $m_mall_content->where($c_map)->find();
				$list[$i]['target_name'] = $u_map['name'];
			}
		}
		
		#dump($f_data);die;
		$this->assign("list",$list);
		$this->assign("f_data",$f_data);
		$this->display();
	}
	
	public function Create_rankings(){
		$m_cms_content = M("cms_content");
		$m_mall_content = M("mall_content");
		
		if(IS_POST){
			$data = I("");
			
			//dump($data);die;
		}else{
			#风格
			$style_map['type'] = get_mall_model_conf('MALL_STYLE');
			$style_map['status'] = 1;
			$style_list = $m_mall_content->where($style_map)->select();
			
			#排行类型
			$rtyle_style_map['type'] = get_cms_model_conf('CMS_RANKING_STYLE');
			$rtyle_style_map['status'] = 1;
			$rtyle_style_list = $m_cms_content->where($rtyle_style_map)->select();
			
			#时间
			$time_map['type'] = get_cms_model_conf('CMS_TIME');
			$time_map['status'] = 1;
			$time_list = $m_cms_content->where($time_map)->select();
			
			#排行的种类  单曲、专辑、音乐人
			$type_map['type'] = get_cms_model_conf('CMS_RANKING_TYPE');
			$type_map['status'] = 1;
			$type_list = $m_cms_content->where($type_map)->select();
			
			$this->assign("style_list",$style_list);
			$this->assign("rtyle_style_list",$rtyle_style_list);
			$this->assign("time_list",$time_list);
			$this->assign("type_list",$type_list);
			$this->display();	
		}
		
	}
	
	#从所有音乐人，专辑，活动中选择排序
	public function Ranking_lists(){
		$m_common_user = M("common_user");
		$m_mall_content = M("mall_content");
		#类型   1单曲    2专辑   3音乐人
		$type = I('param.type');
		$name = I("param.name");
		$uid = I("param.uid");
		$form_id = I("param.form_id");
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$time  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		$this->assign("begin_time",$begin_time);
		$this->assign("end_time",$end_time);
		
		
		if($type == 1){
			
			#所有单曲
			if($time){
				$song_map['time'] = $time;
			}
			if($name){
				$song_map['name'] = array("like",$name);
			}
			
			$song_map['type'] = 15;
			$song_map['status'] = 1;
			$list = $m_mall_content->where($song_map)->page($_GET['p'].',30')->select();
			#所属人
			foreach($list as $i=>$v){
				$u_map['id'] = $list[$i]['uid'];
				$u_data = $m_common_user->where($u_map)->find();
				$list[$i]['nickname'] = $u_data['nickname'];
			}
			$this->assign('begin_time',$begin_time);
			$this->assign('end_time',$end_time);
			
			$count      = $m_mall_content->where($song_map)->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
			$show       = $Page->show();// 分页显示输出
		}else if($type == 2){
			#所有专辑
			if($time){
				$album_map['time'] = $time;
			}
			if($name){
				$album_map['name'] = array("like",$name);
			}
			$album_map['type'] = 16;
			$album_map['status'] = 1;
			$list = $m_mall_content->where($album_map)->page($_GET['p'].',30')->select();
			#所属人
			foreach($list as $i=>$v){
				$u_map['id'] = $list[$i]['uid'];
				$u_data = $m_common_user->where($u_map)->find();
				$list[$i]['nickname'] = $u_data['nickname'];
				
			}
			
			$count      = $m_mall_content->where($album_map)->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
			$show       = $Page->show();// 分页显示输出
		}else if($type == 3){
			#所有音乐人
			if($time){
				$user_map['create_time'] = $time;
			}
			if($name){
				$user_map['name'] = array("like",$name);
			}
			$user_map['group_id'] = 9;
			$user_map['status'] = 1;
			$list = $m_common_user->where($user_map)->page($_GET['p'].',30')->select();
			#dump($user_map);die;
			$count      = $m_common_user->where($user_map)->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
			$show       = $Page->show();// 分页显示输出
		}
		
		
		$this->assign("page",$show);
		$this->assign("form_id",$form_id);
		$this->assign("type",$type);
		$this->assign("list",$list);
		$this->display();
	}
	
	
	#添加排行榜内栏目
	public function add_ranking(){
		$m_common_user_ranking = M("common_user_ranking");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		//判断是否是ajax请求
		if(IS_AJAX){
			$id = $id?$id:I('param.id');
			$type = I('param.type');
			$form_id = I('param.form_id');
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					if($id[$i] > 0 and $type > 0){
						$map['target_id'] = $id[$i];
						$map['type'] = $type;
						$map['form_id'] = $form_id;
						
						#根据类型 查询名称
						if($type == 3){
							$u_map['id'] = $id[$i];
							$u_data = $m_common_user->where($u_map)->find();
							$name =  $u_data['nickname'];
						}else{
							$u_map['id'] = $id[$i];
							$u_data = $m_mall_content->where($u_map)->find();
							$name =  $u_data['name'];
						}
						
						$result = $m_common_user_ranking->where($map)->find();
						if($result){
							$m_common_user_ranking->delete($map);
						}else{
							$map['name'] = $name;
							$map['time'] = time();
							$map['status'] = 1;
							$m_common_user_ranking->add($map);
						}
					}
					
				}
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
		
		
	}
	
	
	/**
	 * 批量改变页面状态
	 */
	public function save_ranking($id,$sort=0){
		
		//判断是否是ajax请求
		if(IS_AJAX){
			$m_common_user_ranking = M("common_user_ranking");
			$id = $id?$id:I('param.id');
			$sort = $sort?$sort:I('param.sort');
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['sort'] = $sort;
					$m_common_user_ranking->where($map)->save($data);
				}
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
	}
	
	
	/**
	 * 批量删除菜单
	 */
	public function delete_money($id,$status=0){
		
	
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_mall_content_money = M('mall_content_money');
		
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['status'] = $status;
					$m_mall_content_money->where($map)->delete();
					
				}
				//返回信息
				$info = get_errcode(0);
			}else{
				$info = get_errcode(10000001);
			}
		}
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
	}
	
	
}